<?php

  //////////////////////////////////////////////////////////////////
  // OrbitFAQ                                                     //
  // ---------                                                    //
  //                                                              //
  // Orbit FAQ was solely written and developed by Orbit Services //
  // http://www.orbitservices.net                                 //
  //                                                              //
  // Access the Forum here:                                       //
  // http://forums.orbitservices.net/index.php?c=4                //
  //                                                              //
  // OrbitFAQ utilises the following opensource projects/classes; //
  //  + Fckeditor - http://www.fckeditor.net                      //
  //  + Smarty Template Engine - http://smarty.php.net            //
  //  + Swift Email Class - http://www.swiftmailer.org/           //
  //  + OWASP PHP Filter Project - http://www.owasp.org           //
  //  + MySQL Search Class by Stephen Bartholomew                 //
  //                                                              //
  //////////////////////////////////////////////////////////////////

  $smarty->assign("OrbitFAQTitle","FAQ Configuration");

  if($accesslvl != 'superadmin')
    {

      // Tell the user that they dont have access to this module
      $message = "You do not have access to this module.";
      $smarty->assign("message","$message");

      $smarty_template_file = "$AdminFullPath/skins/$AdminSkin/mod_auth_bannedip.tpl";
      $smarty->display("file:$smarty_template_file");

      clearSmartyCompiled($SmartyCompileDir, $ClearSmartyCompiled);
      exit;

    }

    $smarty_template_file = "$AdminFullPath/skins/$AdminSkin/mod_config.tpl";

    if($posted == 'yes')
      {

        $query_config = "SELECT * from orbitfaq_config";
        $result_config = $faqsql_query ($query_config)OR DIE( "$sql_query_error $query_config");

        while($row_config = $faqsql_fetch_array($result_config))
          {

            $config_id = $row_config[0];
            $config_group = $row_config[1];
            $config_variable = $row_config[2];
            $config_value = $row_config[3];
            $config_desc = $row_config[4];
            $config_options = $row_config[5];
            $config_default = $row_config[6];
            $config_madatory = $row_config[7];

            $new_value = $_POST[$config_variable];

            //echo "$config_variable|$new_value<br />";

            if((($config_madatory == '1')AND($new_value != ''))OR($config_madatory == '0'))
              {

                $query = "UPDATE `orbitfaq_config` SET `value` = '$new_value' WHERE `id` = '$config_id'";
                $result = $faqsql_query ($query)OR DIE( "$sql_query_error $query_config");

              }
            else if(($config_madatory == '1')AND($new_value == ''))
              {

                $error = " however some values were not updated due to errors";

              }

          }


         clearSmartyCompiled($SmartyCompileDir, $ClearSmartyCompiled);

         $message = "Config Updated$error!";
         header("Location: index.php?mod=$mod&message=$message");

         exit;

      }

    // Get our Config Settings
    $query_config = "SELECT * from orbitfaq_config";
    $result_config = $faqsql_query ($query_config)OR DIE( "$sql_query_error $query_config");;

    while($row_config = $faqsql_fetch_array($result_config))
      {

        $config_id = $row_config[0];
        $config_group = $row_config[1];
        $config_variable = $row_config[2];
        $config_value = $row_config[3];
        $config_desc = $row_config[4];
        $config_options = $row_config[5];
        $config_default = $row_config[6];
        $config_madatory = $row_config[7];

        if($config_options != '')
          {

            $config_options = trim($config_options);
            $options = split(",", $config_options);

            foreach($options as $option)
              {

                $od = explode("|", $option);
                $option_value = $od[0];
                $option_desc =  $od[1];

                $config_options_html .= "<option value=\"$option_value\"";
                if($option_value == $config_value){ $config_options_html .= " selected"; }
                $config_options_html .= ">$option_desc";
                if($option_value == $config_default){ $config_options_html .= " (default)"; }
                $config_options_html .= "</option>";
              }

            $config_fieldtype = 'pulldown';

          }
        else
          {
            $config_fieldtype = '';
          }

          if($config_group == 'faqdetails')
            {

               // Build Smarty Content Array
               $smarty_faqdetails_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_madatory" => "$config_madatory",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }
          elseif($config_group == 'folders')
            {

               // Build Smarty Content Array
               $smarty_folders_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }
          elseif($config_group == 'email')
            {

               // Build Smarty Content Array
               $smarty_email_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }
          elseif($config_group == 'phpconfig')
            {

               // Build Smarty Content Array
               $smarty_phpconfig_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }
          elseif($config_group == 'skins')
            {

         // Build Smarty Content Array
         $smarty_skins_array[] = array(
            "config_id" => "$config_id",
            "config_group" => "$config_group",
            "config_variable" => "$config_variable",
            "config_value" => "$config_value",
            "config_desc" => "$config_desc",
            "config_options" => "$config_options_html",
            "config_default" => "$config_default",
            "config_fieldtype" => "$config_fieldtype"
          );

            }
          elseif($config_group == 'faqratings')
            {

               // Build Smarty Content Array
               $smarty_faqratings_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }
          elseif($config_group == 'rss')
            {


               // Build Smarty Content Array
               $smarty_rss_array[] = array(
                  "config_id" => "$config_id",
                  "config_group" => "$config_group",
                  "config_variable" => "$config_variable",
                  "config_value" => "$config_value",
                  "config_desc" => "$config_desc",
                  "config_options" => "$config_options_html",
                  "config_default" => "$config_default",
                  "config_fieldtype" => "$config_fieldtype"
                );

            }

        $config_options_html = '';

  }

  // Send our Smarty Data
  $smarty->assign('ConfigFAQDetailsListing',$smarty_faqdetails_array);

  // Send our Smarty Data
  $smarty->assign('ConfigFoldersListing',$smarty_folders_array);

  // Send our Smarty Data
  $smarty->assign('ConfigEmailListing',$smarty_email_array);

  // Send our Smarty Data
  $smarty->assign('ConfigPHPListing',$smarty_phpconfig_array);

  // Send our Smarty Data
  $smarty->assign('ConfigSkinsListing',$smarty_skins_array);

  // Send our Smarty Data
  $smarty->assign('ConfigRatingListing',$smarty_faqratings_array);


  // Send our Smarty Data
  $smarty->assign('ConfigRSSListing',$smarty_rss_array);

?>